package com.bw.goods.service.impl;

import com.bw.goods.entity.vo.MiaoShaVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bw.common.utils.PageUtils;
import com.bw.common.utils.Query;

import com.bw.goods.dao.GoodsDao;
import com.bw.goods.entity.GoodsEntity;
import com.bw.goods.service.GoodsService;


@Service("goodsService")
public class GoodsServiceImpl extends ServiceImpl<GoodsDao, GoodsEntity> implements GoodsService {

    @Autowired
    private GoodsDao goodsDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<GoodsEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if(StringUtils.isNotEmpty(key)) {
            wrapper.like("goodsName",key);
        }
        IPage<GoodsEntity> page = this.page(
                new Query<GoodsEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public MiaoShaVO getVo(Integer goodsId) {

        return goodsDao.getVo(goodsId);
    }

    @Override
    public List<GoodsEntity> slist() {
        List<GoodsEntity> list = goodsDao.selectList(null);
        return list;
    }

}